import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution1282 {
    public List<List<Integer>> groupThePeople(int[] groupSizes) {
        List<List<Integer>> ans=new ArrayList<>();
        Map<Integer,List<Integer>> map=new HashMap<>();
        for (int i=0;i< groupSizes.length;i++){
            if (!map.containsKey(groupSizes[i])){
                map.put(groupSizes[i],new ArrayList<>());
            }
            map.get(groupSizes[i]).add(i);
            if (map.get(groupSizes[i]).size()==groupSizes[i]){
                ans.add(map.get(groupSizes[i]));
                map.remove(groupSizes[i]);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1282().groupThePeople(new int[]{3,3,3,3,3,1,3}));
    }
}
